package com.person.jc.service.base.fault;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.person.jc.service.Service;
import com.person.jc.utils.Utils;

public class BdFaultInfoService extends Service {
	
	public final static BdFaultInfoService me = new BdFaultInfoService();
	
	public List<Record> getList(Map<String,Object> map){
		List<Object> params = new ArrayList<Object>();
		String temp = "";
		StringBuffer sql = new StringBuffer("select t.* from bd_fault_info t where if_valid = 1 ");
		if(Utils.isNotEmpty(temp = String.valueOf(map.get("faultId")))){
			sql.append(" and fault_id = ?");
			params.add(temp);
		}
		if(Utils.isNotEmpty(temp = String.valueOf(map.get("faultName")))){
			sql.append(" and fault_name like ?");
			params.add("%"+temp+"%");
		}
		sql.append(" order by device_type");
		return Db.find(sql.toString(), Utils.getObjParam(params));
	}
	
	public void save(Map<String,Object> map){
//		String sql = "insert into bd_fault_info(fault_name, device_type, remark) values (?,?,?)";
//		Db.update(sql, map.get("faultName"), map.get("deviceType"), map.get("remark"));
		String sql = "insert into bd_fault_info(fault_name, remark) values (?,?)";
		Db.update(sql, map.get("faultName"), map.get("remark"));
		super.setCRUD("设备故障现象", "C", "新增设备故障现象："+map.get("faultName"));
	}
	
	public void update(Map<String,Object> map){
//		String sql = " update bd_fault_info set fault_name = ? , device_type = ?, remark = ? where fault_id = ?";
//		Db.update(sql, map.get("faultName"), map.get("deviceType"), map.get("remark"), map.get("faultId"));
		String sql = " update bd_fault_info set fault_name = ?, remark = ? where fault_id = ?";
		Db.update(sql, map.get("faultName"), map.get("remark"), map.get("faultId"));
		super.setCRUD("设备故障现象", "U", "修改设备故障现象："+map.get("faultId"));
	}
	
	public void delete(String id){
		String sql = " update bd_fault_info set if_valid = 0 where fault_id = ?";
		Db.update(sql, id);
		super.setCRUD("设备故障现象", "D", "删除设备故障现象："+id);
	}
	
}
